//
//  TSTaskListController.m
//  chart
//
//  Created by 曾斌 on 16/3/24.
//  Copyright (c) 2016年 xu. All rights reserved.
//



#import "TSTaskListController.h"
#import "TSTaskTableView.h"
#import "TSCreateScheduleViewController.h"
#import "TSRecycleMsgListViewController.h"
#import "TSPraiseTabBarController.h"
#import "TSAuditTabBarController.h"
#import "TSSendTabBarController.h"
#import "TSSuperviseTabBarController.h"
#import "TSCreateTaskTabBarController.h"
#import "TSFinishTabBarController.h"
@interface TSTaskListController ()

@end

@implementation TSTaskListController{
    
}
@synthesize tableView;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUserViewController:) name:TSNotification_ScheduleCreateSucceeded object:nil];
    
    //self.navigationItem.title = @"个人日程";
    
    WS(weakSelf);
    UIActionSheet *action_sheet =[self createActionSheet];
    if(action_sheet){
        [self rightBarButtonWithTitle:nil barNorImage:[UIImage imageNamed:@"topic_follow_add"] barHltImage:nil action:^{
            if (!weakSelf) {
                return;
            }
            [action_sheet showInView:weakSelf.view];
        }];
    }
    
    tableView =[self createTableView];
    [self.view addSubview:tableView];
    [tableView.header beginRefreshing];
}

-(TSTaskTableView *)createTableView{
    return [[TSTaskTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

}

-(UIActionSheet *)createActionSheet
{
    WS(weakSelf);
  return [[UIActionSheet alloc] initWithTitle:nil delegate:weakSelf cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"创建任务",@"发送任务",@"审核任务",@"监督任务",@"任务点赞",@"完结任务", nil];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        //创建任务
        TSCreateTaskTabBarController *tab_bar = [[TSCreateTaskTabBarController alloc] init];
        [self presentViewController:tab_bar animated:YES completion:nil];
    }else if (buttonIndex == 1) {
        //发送任务
        TSSendTabBarController *tab_bar = [[TSSendTabBarController alloc] init];
        [self presentViewController:tab_bar animated:YES completion:nil];
    }else if (buttonIndex == 2) {
        //审核任务
        TSAuditTabBarController *tab_bar = [[TSAuditTabBarController alloc] init];
        [self presentViewController:tab_bar animated:YES completion:nil];
    }
    else if (buttonIndex == 3) {
        //监督任务
        TSSuperviseTabBarController *tab_bar = [[TSSuperviseTabBarController alloc] init];
        [self presentViewController:tab_bar animated:YES completion:nil];
    }
    else if (buttonIndex == 4) {
        //任务点赞
        TSPraiseTabBarController *tab_bar = [[TSPraiseTabBarController alloc] init];
        [self presentViewController:tab_bar animated:YES completion:nil];
    }
    else if (buttonIndex == 5) {
        //完结任务
        TSFinishTabBarController *tab_bar = [[TSFinishTabBarController alloc] init];
        [self presentViewController:tab_bar animated:YES completion:nil];
    }
}


- (void)refreshUserViewController:(NSNotification *)noti
{
    if (tableView) {
        [tableView.header beginRefreshing];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end

